/*
 *     Copyright 2000-2011 Francois de Bertrand de Beuvron
 * 
 *     This file is part of CoursBeuvron.
 * 
 *     CoursBeuvron is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     CoursBeuvron is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with CoursBeuvron.  If not, see <http://www.gnu.org/licenses/>.
 */
package fr.insa.beuvron.tps.m2.dessin2DV3.gui;

import fr.insa.beuvron.tps.m2.dessin2DV3.EnsembleFigure;
import fr.insa.beuvron.tps.m3.gui.TestePanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

/**
 *
 * @author francois
 */
public class InterfacePartielle4 extends JPanel implements ActionListener, MouseListener {

    private JSplitPane jsplit1;
    private InterfacePartielle3 ipTexte;
    private JPanel jpDessin;
    private FigurePanel igDessin;
    private JPanel jpBoutons;
    private JButton jbZommToFit;
    private JButton jbZoomPlus;
    private JButton jbZoomMoins;
    private JLabel jlComment;
    private EnsembleFigure figs;

    public InterfacePartielle4(EnsembleFigure figs) {
        this.setLayout(new BorderLayout());
        this.figs = figs;
        this.ipTexte = new InterfacePartielle3(figs);
        this.jpDessin = new JPanel(new BorderLayout());

        this.jpBoutons = new JPanel();
        this.jbZommToFit = new JButton("Zoom Tout Voir");
        this.jbZommToFit.addActionListener(this);
        this.jpBoutons.add(this.jbZommToFit);
        this.jbZoomPlus = new JButton("Zoom *2");
        this.jbZoomPlus.addActionListener(this);
        this.jpBoutons.add(this.jbZoomPlus);
        this.jbZoomMoins = new JButton("Zoom /2");
        this.jbZoomMoins.addActionListener(this);
        this.jpBoutons.add(this.jbZoomMoins);
        this.jpDessin.add(this.jpBoutons, BorderLayout.NORTH);

        this.jlComment = new JLabel("venez dans le panneau !");
        this.jpDessin.add(this.jlComment, BorderLayout.SOUTH);

        this.igDessin = new FigurePanel(figs);
        this.igDessin.addMouseListener(this);
        this.jpDessin.add(this.igDessin, BorderLayout.CENTER);
        this.jsplit1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, this.ipTexte, this.jpDessin);
        this.add(this.jsplit1, BorderLayout.CENTER);

    }

    public static void main(String[] args) {
        EnsembleFigure figs = new EnsembleFigure();
        figs.ajoutePointOuSegmentAlea(20, 0.3, 10);
        InterfacePartielle4 i2 = new InterfacePartielle4(figs);
        TestePanel.tailleFixee("interface demo3", i2, 800, 600);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == this.jbZommToFit) {
            this.igDessin.zoomToFit();
            this.igDessin.repaint();
        } else if (e.getSource() == this.jbZoomMoins) {
            this.igDessin.zoomFacteur(0.5);
            this.igDessin.repaint();
        } else if (e.getSource() == this.jbZoomPlus) {
            this.igDessin.zoomFacteur(2);
            this.igDessin.repaint();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getSource() == this.igDessin) {
            double[] coordPanel = new double[2];
            coordPanel[0] = e.getX();
            coordPanel[1] = e.getY();
            double[] coordFig = this.igDessin.coordFigure(coordPanel);
            this.jlComment.setText("clic en panel("
                    + coordPanel[0] + "," + coordPanel[1] + ") = figure("
                    + coordFig[0] + "," + coordFig[1] + ")");
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // ne rien faire
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // ne rien faire
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        this.jlComment.setText("et maintenant cliquez !");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        this.jlComment.setText("venez dans le panneau !");
    }
}
